<template>
  <div class="container-count">
    <button class="operator" @click="add">+</button>
    <input :value="value" class="inp" type="text" @change="valueChange">
    <button class="operator" @click="minus">-</button>
  </div>
</template>

<script>
export default {
    props:['value'],
    methods: {
        add(){ 
            this.$emit('input', this.value + 1)
        },
        minus(e){
            // 判断最小
            if(this.value <= 1) return 
            this.$emit('input', this.value - 1)
        },
        valueChange(e){

            const num = +e.target.value
            if(isNaN(num) || num <= 0) {
                e.target.value = this.value
                return
            }

            // if(e.target.value <= 1) return
            this.$emit('input', e.target.value)
        }


    }
}
</script>

<style lang="less" scoped>
.container-count {
    

    width: 110px;
    height: 30px;
    display: flex;
    flex-direction: row;

    .operator {
        border: none;
        outline: none;
        background-color: #eee;
        width: 30px;
        height: 100%;
    }

    .inp {
        width: 40px;
        height: 100%;
        margin: 0 5px;
        text-align: center;
        font-size: 13px;
    }


}
</style>